home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 January - Disc 2 / Macworld (1999-01) (Disk 2).dmg / Serious Demos / Symbolic Composer 4.2 / Environment / Projects / Questions & Answers / Q&A Programming Functions / Def-class accepting variables < prev    next >
Encoding:
Text File  |  1998-10-26  |  1.4 KB  |  65 lines  |  [TEXT/ScoM]

  1. MAKING DEF-CLASS ACCEPT VARIABLES
  2.  
  3. >one question:
  4. >;********
  5. >(setq
  6. >sect 's1
  7. >instrument 'i2
  8. >sym (nreverse '(a b c d e f))
  9. >)
  10. >
  11. >(def-class symbol instrument sect sym)
  12. >
  13. >;Why I can't set the class through its variables
  14. >
  15. >(same-as symbol of i2 in s1) ;<-- I want this
  16. >
  17. >(same-as symbol of instrument in sect) ;<-- but I get this
  18. >;********
  19. >
  20. >Is possible to directly define the class inside a section 
  21. >without using the macro def-class or def-section?
  22. >(something like make-instance or slot-value)
  23. >
  24. >I can not use def-class inside a function or macro 
  25. >using variables for instruments and sections
  26.  
  27. You must use backquote. 
  28.  
  29. (setq sym '(a b c))
  30. (setq instrument 'i2)
  31. (setq sect 's1)
  32.  
  33. (eval `(def-class symbol ,instrument ,sect ',sym))
  34.  
  35. (same-as symbol of i2 in s1)
  36. --> (a b c)
  37.  
  38. Explanation
  39.  
  40. Backquote quotes the list except those elements which are 
  41. preceded by , which evaluates the contents. Hence when
  42. you evaluate this once
  43.  
  44. `(def-class symbol ,instrument ,sect ',sym)
  45.  
  46. it creates the following code
  47.  
  48. (def-class symbol i2 s1 '(a b c))
  49.  
  50. When you evaluate it second time it makes class definition.
  51.  
  52. Use do-quietly to get rid of listener messages.
  53.  
  54. (defun define-my-classes ()
  55.   (let ((sym '(a b c))
  56.         (instrument 'i2)
  57.         (sect 's1))
  58.     (do-quietly
  59.       (eval `(def-class symbol ,instrument ,sect ',sym)))))
  60.  
  61. (define-my-classes)
  62. (same-as symbol of i2 in s1)
  63. --> (a b c)
  64.  
  65.